package com.android.component;

import android.os.Bundle;
import android.view.View;

import com.mapper.JsonMapper;
import com.mapper.Test1;
import com.utils.HTRinger;
import com.utils.LogUtil;

import org.json.JSONException;
import org.json.JSONObject;


public class JSonMapTest extends CommonTest {
    private static final String TAG = "JSonMapTest";
    HTRinger ringer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ringer = new HTRinger(this);
        setButton("测试", onClickListener);


    }

    View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (v == btns[0]) {
                JSONObject jsonObject = new JSONObject();

                try {
                    jsonObject.put("center", 1);
                    jsonObject.put("a", 12);
                    jsonObject.put("b", 34);
                    jsonObject.put("c", 56);
                    jsonObject.put("x", 9.45);
                    jsonObject.put("y", 34.3445);

                    jsonObject.put("center1", 11);
                    jsonObject.put("a1", 112);
                    jsonObject.put("b1", 314);
                    jsonObject.put("c1", 516);
                    jsonObject.put("x1", 91.45);
                    jsonObject.put("y1", 314.3445);

                    jsonObject.put("name", "你大爷");

                    JsonMapper mapper = new JsonMapper();

                    Test1 test1 = new Test1();
                    mapper.parseJson(test1, jsonObject.toString());

                    LogUtil.d(TAG, "test1.center" + test1.center);
                    LogUtil.d(TAG, "test1.a" + test1.a);
                    LogUtil.d(TAG, "test1.b" + test1.b);
                    LogUtil.d(TAG, "test1.c" + test1.c);
                    LogUtil.d(TAG, "test1.x" + test1.x);
                    LogUtil.d(TAG, "test1.y" + test1.y);

                    LogUtil.d(TAG, "test1.center1" + test1.center1);
                    LogUtil.d(TAG, "test1.a1" + test1.a1);
                    LogUtil.d(TAG, "test1.b1" + test1.b1);
                    LogUtil.d(TAG, "test1.c1" + test1.c1);
                    LogUtil.d(TAG, "test1.x1" + test1.x1);
                    LogUtil.d(TAG, "test1.y1" + test1.y1);

                    LogUtil.d(TAG, "test1.name" + test1.name);


                } catch (JSONException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    };
}
